define([
		"Underscore",
		"Backbone",
		"js/view/CategoriesView"
	], function(_, Backbone, CategoriesView) {

	return Backbone.View.extend({
		tagName: "aside",
		blogCategoriesUrl: "http://springleafweb.appspot.com/get-all-categories",

		initialize: function() {
			console.log("BlogAsideView - Initialize");

			this.categoriesView = new CategoriesView({
				model: this.model
			});

			this.requestCategories();
		},

		render: function() {
			console.log("BlogAsideView - Render");

			this.$el.empty().append(this.categoriesView.render().el);

			return this;
		},

		requestCategories: function() {
			console.log("BlogAsideView - Request ~ Categories");

			var self = this;

			$.get(this.blogCategoriesUrl, function(event) {
				if (event.error == null && event != "") {
					self.model.set("categories", event.data);
				} else {
					alert("Error getting the categories");
				}
			}).error(function() {
				event = {
					action: "GET_ALL_CATEGORIES",
					data: [{
						id: "35002",
						value: "Java"
					}, {
						id: "36003",
						value: "ActionScript 3.0"
					}, {
						id: "37001",
						value: "Game Design"
					}, {
						id: "93001",
						value: "JavaScript"
					}, {
						id: "93002",
						value: "AutoIt"
					}, {
						id: "94001",
						value: "Object-Oriented Programming"
					}]
				};
				self.model.set("categories", event.data);
			});
		}
	});
});